#!/bin/bash
echo '开始构建项目'
#构建函数
function bulid() {
 lasts=`echo $1 | awk -F '/' '{printf "%d", length($0)-length($NF)}'`
 lastPonit=`echo  $1 | awk -F '.' '{printf "%d", length($0)-length($NF)}'`
 if test  $lasts; then
# echo $lasts
 result=${1:lasts}
 point=`echo  $result | awk -F '.' '{printf "%d", length($0)-length($NF)}'`
 result=${result:0:point-1}
else
 echo '项目名称处理失败！'
 exit 1
fi
 echo $result
 cd ../$result
if  git pull;
 then
  echo '分支更新代码完成'
 else
  exit 1
  echo '分支代码更新失败'
 fi
 cd ./target
if  mkdir docker; then
 echo 'docker 目录成功'
else
　echo '目录失败'
fi
 cd docker
 echo 'pwd'
 mv ../$result-1.0.0-SNAPSHOT.jar ./
 cp /home/oo/IdeaProjects/hzx/bulid/dock/Dockerfile ./
 if  docker build --build-arg PROJECT_NAME=$result  -t $result:1.0 . ;
 then
   echo '构建成功'
 else
   echo '构建失败$result'
 fi
 cd ../../../bulid/
}
echo '读取配置文件加载构建包'
for line in `cat /home/oo/IdeaProjects/hzx/bulid/project.text`
do
 bulid $line
done
